package Solutions;

/**
 * @Classname IsSymmetricTree
 * @Description TODO
 * @Date 2021/6/21 10:23
 * @Created by LengDanran
 * https://leetcode-cn.com/problems/symmetric-tree/submissions/
 */
public class IsSymmetricTree {

    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public boolean isSymmetric(TreeNode root) {
        if (root == null) return true;
        return inorder(root.left, root.right);
    }

    public boolean inorder(TreeNode left, TreeNode right) {
        if (left == null && right == null) return true;
        if (left == null || right == null) return false;
        if (left.val != right.val) return false;
        return inorder(left.left, right.right) && inorder(left.right, right.left);
    }

    public static void main(String[] args) {

    }
}
